package com.spring.cold.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spring.cold.mapper.BaseMapper;
import com.spring.cold.pojo.BaseEntity;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public abstract class BaseService<T extends BaseMapper<V>,V extends BaseEntity> {
    @Autowired
    protected T mapper;
    public int deleteByPrimaryKey(String id){
        return mapper.deleteByPrimaryKey(id);
    }
    public int insert(V entity){
        return mapper.insert(entity);
    }
    public int insertSelective(V entity){
        return mapper.insertSelective(entity);
    }
    public V selectByPrimaryKey(String id){
        return mapper.selectByPrimaryKey(id);
    }
    public int updateByPrimaryKey(V entity){
        return mapper.updateByPrimaryKey(entity);
    }
    public int updateByPrimaryKeySelective(V entity){
        return mapper.updateByPrimaryKeySelective(entity);
    }
    public PageInfo<V> selectPage(V entity){
        PageHelper.startPage(entity.getPage(),entity.getLimit());
        List<V> list = mapper.selectList(entity);
        return new PageInfo<>(list);
    }
}
